;/*****************************************************************************
; * @file:    startup_MPS_CM3.s
; * @purpose: CMSIS Cortex-M3 Core Device Startup File 
; *           for the ARM 'Microcontroller Prototyping System' 
; * @version: V1.01
; * @date:    19. Aug. 2009
; *------- <<< Use Configuration Wizard in Context Menu >>> ------------------
; *
; * Copyright (C) 2008-2009 ARM Limited. All rights reserved.
; * ARM Limited (ARM) is supplying this software for use with Cortex-M3 
; * processor based microcontrollers.  This file can be freely distributed 
; * within development tools that are supporting such ARM based processors. 
; *
; * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
; * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
; * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
; * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
; * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
; *
; *****************************************************************************/


; <h> Stack Configuration
;   <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Stack_Size      EQU     0x00000400

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp


; <h> Heap Configuration
;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Heap_Size       EQU     0x00000C00

                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem        SPACE   Heap_Size
__heap_limit

;				IMPORT xPortPendSVHandler
;				IMPORT xPortSysTickHandler
;				IMPORT vPortSVCHandler
				IMPORT SysTick_Handler1				

                PRESERVE8
                THUMB


; Vector Table Mapped to Address 0 at Reset

                AREA    RESET, DATA, READONLY
                EXPORT  __Vectors
;                EXPORT  __Vectors_End
;                EXPORT  __Vectors_Size

__Vectors       DCD     __initial_sp              ; Top of Stack
                DCD     Reset_Handler             ; Reset Handler
                DCD     NMI_Handler               ; NMI Handler
                DCD     HardFault_Handler         ; Hard Fault Handler
                DCD     MemManage_Handler         ; MPU Fault Handler
                DCD     BusFault_Handler          ; Bus Fault Handler
                DCD     UsageFault_Handler        ; Usage Fault Handler
                DCD     0                         ; Reserved
                DCD     0                         ; Reserved
                DCD     0                         ; Reserved
                DCD     0                         ; Reserved
                DCD     SVC_Handler               ; SVCall Handler
;                DCD     vPortSVCHandler               ; SVCall Handler
                DCD     DebugMon_Handler          ; Debug Monitor Handler
                DCD     0                         ; Reserved
;                DCD     xPortPendSVHandler            ; PendSV Handler
;                DCD     xPortSysTickHandler          ; SysTick Handler
                DCD     PendSV_Handler            ; PendSV Handler
                DCD     SysTick_Handler1          ; SysTick Handler

	;*===================================================
	;* external interrupt inputs
	;*===================================================
	
       ;-------------<16~23>----------------------------------------------
	DCD		LVDFAIL_Handler						;0
	DCD		SYSCLKFAIL_Handler					;1
	DCD		XOSCFAIL_Handler					;2
	DCD		WDT_Handler							;3
	DCD		NULL_Handler						;4
	DCD		TIMER0_Handler						;5
	DCD		TIMER1_Handler						;6
	DCD		TIMER2_Handler						;7

	;-------------<24~31>----------------------------------------------
	DCD		TIMER3_Handler						;8
	DCD		NULL_Handler						;9
	DCD		NULL_Handler						;10
	DCD		NULL_Handler						;11
	DCD		NULL_Handler						;12
	DCD		TIMER4_Handler						;13
	DCD		TIMER5_Handler						;14
	DCD		NULL_Handler						;15

	;-------------<32~39>----------------------------------------------
	DCD		GPIOAE_Handler						;16
	DCD		GPIOAO_Handler						;17
	DCD		GPIOBE_Handler						;18
	DCD		GPIOBO_Handler						;19
	DCD		GPIOCE_Handler						;20
	DCD		GPIOCO_Handler						;21
	DCD		GPIODE_Handler						;22
	DCD		GPIODO_Handler						;23

	;-------------<40~47>----------------------------------------------
	DCD		MPWM0_Handler						;24
	DCD		MPWM0PROT_Handler					;25
	DCD		MPWM0OVV_Handler					;26
	DCD		MPWM1_Handler						;27
	DCD		MPWM1PROT_Handler					;28
	DCD		MPWM1OVV_Handler					;29
	DCD		NULL_Handler						;30
	DCD		NULL_Handler						;31

	;-------------<48~55>----------------------------------------------
	DCD		SPI0_Handler						;32
	DCD		SPI1_Handler						;33
	DCD		NULL_Handler						;34
	DCD		NULL_Handler						;35
	DCD		I2C0_Handler						;36
	DCD		I2C1_Handler						;37
	DCD		UART0_Handler						;38
	DCD		UART1_Handler						;39

	;-------------<56~63>----------------------------------------------
	DCD		UART2_Handler						;40
	DCD		UART3_Handler						;41
	DCD		NULL_Handler						;42	
	DCD		ADC0_Handler						;43
	DCD		ADC1_Handler						;44
	DCD		ADC2_Handler						;45
	DCD		COMP0_Handler						;46
	DCD		COMP1_Handler						;47

	;-------------<64~71>----------------------------------------------
	DCD		COMP2_Handler						;48
	DCD		COMP3_Handler						;49
	DCD		NULL_Handler						;50
	DCD		NULL_Handler						;51
	DCD		NULL_Handler						;52
	DCD		NULL_Handler						;53
	DCD		NULL_Handler						;54
	DCD		NULL_Handler						;55

	;-------------<72~79>----------------------------------------------		
	DCD		NULL_Handler						;56
	DCD		NULL_Handler						;57
	DCD		NULL_Handler						;58
	DCD		NULL_Handler						;59
	DCD		NULL_Handler						;60
	DCD		NULL_Handler						;61
	DCD		NULL_Handler						;62
	DCD		NULL_Handler						;63

;__Vectors_Size  EQU     __Vectors_End - __Vectors

                AREA    |.text|, CODE, READONLY


; Reset Handler

Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]
                IMPORT  SystemInit
                IMPORT  __main
                LDR     R0, =SystemInit
                BLX     R0
                LDR     R0, =__main
                BX      R0
                ENDP


; Dummy Exception Handlers (infinite loops which can be modified)

NMI_Handler     PROC
                EXPORT  NMI_Handler               [WEAK]
                B       .
                ENDP
HardFault_Handler\
                PROC
                EXPORT  HardFault_Handler         [WEAK]
                B       .
                ENDP
MemManage_Handler\
                PROC
                EXPORT  MemManage_Handler         [WEAK]
                B       .
                ENDP
BusFault_Handler\
                PROC
                EXPORT  BusFault_Handler          [WEAK]
                B       .
                ENDP
UsageFault_Handler\
                PROC
                EXPORT  UsageFault_Handler        [WEAK]
                B       .
                ENDP
SVC_Handler     PROC
                EXPORT  SVC_Handler               [WEAK]
                B       .
                ENDP
DebugMon_Handler\
                PROC
                EXPORT  DebugMon_Handler          [WEAK]
                B       .
                ENDP
PendSV_Handler  PROC
                EXPORT  PendSV_Handler            [WEAK]
                B       .
                ENDP
;SysTick_Handler PROC
;                Extern  SysTick_Handler           [WEAK]
;               B       .
;               ENDP

NULL_Handler PROC

                EXPORT  LVDFAIL_Handler			[WEAK]
                EXPORT  SYSCLKFAIL_Handler		[WEAK]
                EXPORT  XOSCFAIL_Handler		[WEAK]
                EXPORT  WDT_Handler				[WEAK]
                EXPORT  TIMER0_Handler			[WEAK]
                EXPORT  TIMER1_Handler			[WEAK]              
                EXPORT  TIMER2_Handler			[WEAK]
                EXPORT  TIMER3_Handler			[WEAK]
                EXPORT  TIMER4_Handler			[WEAK]
                EXPORT  TIMER5_Handler			[WEAK]              
                EXPORT  GPIOAE_Handler			[WEAK]
                EXPORT  GPIOAO_Handler			[WEAK]                      
                EXPORT  GPIOBE_Handler			[WEAK]
                EXPORT  GPIOBO_Handler			[WEAK]                      
                EXPORT  GPIOCE_Handler			[WEAK]
                EXPORT  GPIOCO_Handler			[WEAK]                      
                EXPORT  GPIODE_Handler			[WEAK]
                EXPORT  GPIODO_Handler			[WEAK]           
                EXPORT  MPWM0_Handler			[WEAK]
                EXPORT  MPWM0PROT_Handler		[WEAK]       
                EXPORT  MPWM0OVV_Handler		[WEAK]         
                EXPORT  MPWM1_Handler			[WEAK]
                EXPORT  MPWM1PROT_Handler		[WEAK]       
                EXPORT  MPWM1OVV_Handler		[WEAK]
                EXPORT  SPI0_Handler			[WEAK]
                EXPORT  SPI1_Handler			[WEAK] 
                EXPORT  I2C0_Handler			[WEAK]   
                EXPORT  I2C1_Handler			[WEAK]                     
                EXPORT  UART0_Handler			[WEAK]
                EXPORT  UART1_Handler			[WEAK]
                EXPORT  UART2_Handler			[WEAK]
                EXPORT  UART3_Handler			[WEAK]
                EXPORT  ADC0_Handler			[WEAK]
                EXPORT  ADC1_Handler			[WEAK]
                EXPORT  ADC2_Handler			[WEAK]
                EXPORT  COMP0_Handler			[WEAK]
                EXPORT  COMP1_Handler			[WEAK]
                EXPORT  COMP2_Handler			[WEAK]
                EXPORT  COMP3_Handler			[WEAK]

LVDFAIL_Handler    
SYSCLKFAIL_Handler
XOSCFAIL_Handler   
WDT_Handler         
TIMER0_Handler      
TIMER1_Handler      
TIMER2_Handler      
TIMER3_Handler      
TIMER4_Handler      
TIMER5_Handler      
GPIOAE_Handler      
GPIOAO_Handler        
GPIOBE_Handler      
GPIOBO_Handler        
GPIOCE_Handler      
GPIOCO_Handler        
GPIODE_Handler      
GPIODO_Handler      
MPWM0_Handler       
MPWM0PROT_Handler   
MPWM0OVV_Handler  
MPWM1_Handler
MPWM1PROT_Handler   
MPWM1OVV_Handler    
SPI0_Handler        
SPI1_Handler        
I2C0_Handler        
I2C1_Handler        
UART0_Handler       
UART1_Handler       
UART2_Handler       
UART3_Handler       
ADC0_Handler        
ADC1_Handler        
ADC2_Handler        
COMP0_Handler       
COMP1_Handler       
COMP2_Handler       
COMP3_Handler       
                B       .

                ENDP


                ALIGN


; User Initial Stack & Heap

                IF      :DEF:__MICROLIB
                
                EXPORT  __initial_sp
                EXPORT  __heap_base
                EXPORT  __heap_limit
                
                ELSE
                
                IMPORT  __use_two_region_memory
                EXPORT  __user_initial_stackheap
__user_initial_stackheap

                LDR     R0, =  Heap_Mem
                LDR     R1, =(Stack_Mem + Stack_Size)
                LDR     R2, = (Heap_Mem +  Heap_Size)
                LDR     R3, = Stack_Mem
                BX      LR
;                ENDP

                ALIGN

                ENDIF


                END
